import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
import _InputBase from "@mui/material/InputBase";
import React, { useMemo } from "react";
import classNames from "classnames";
import { useControllableValue } from "ahooks";
import classes from "./input.module.less";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
function Input(props) {
    var _props_classes, _props_classes1, _props_classes2, _props_classes3, _props_classes4;
    var defaultValue = props.defaultValue, maxLength = props.maxLength, className = props.className, readonly = props.readonly, suffixIcon = props.suffixIcon, inputClassName = props.inputClassName, clear = props.clear, showMaxLength = props.showMaxLength, reset = _object_without_properties(props, [
        "defaultValue",
        "maxLength",
        "className",
        "readonly",
        "suffixIcon",
        "inputClassName",
        "clear",
        "showMaxLength"
    ]);
    var _useControllableValue = _sliced_to_array(useControllableValue(props, {
        defaultValue: props.defaultValue || "",
        valuePropName: "value",
        trigger: "onChange"
    }), 2), value = _useControllableValue[0], setValue = _useControllableValue[1];
    var readOnlyDom = useMemo(function() {
        var _props_classes;
        return /*#__PURE__*/ _jsx("div", {
            className: classNames(classes.input, (_props_classes = props.classes) === null || _props_classes === void 0 ? void 0 : _props_classes.input),
            children: /*#__PURE__*/ _jsx("span", {
                children: value
            })
        });
    }, [
        value,
        (_props_classes = props.classes) === null || _props_classes === void 0 ? void 0 : _props_classes.input
    ]);
    var changeValue = function(val) {
        if (props.maxLength && val.length > props.maxLength) return;
        setValue(val);
    };
    return /*#__PURE__*/ _jsx("div", {
        className: classNames(classes.input_control, props.className),
        onClick: props.onClick,
        children: /*#__PURE__*/ _jsxs("div", {
            className: classNames(classes.input_wrap, (_props_classes1 = props.classes) === null || _props_classes1 === void 0 ? void 0 : _props_classes1.wrap),
            children: [
                /*#__PURE__*/ _jsx("div", {
                    className: classNames(classes.input, (_props_classes2 = props.classes) === null || _props_classes2 === void 0 ? void 0 : _props_classes2.input),
                    children: props.readonly ? readOnlyDom : /*#__PURE__*/ _jsx(_InputBase, _object_spread_props(_object_spread({}, reset), {
                        className: classNames(classes.input_ui, inputClassName),
                        value: value,
                        onChange: function(e) {
                            return changeValue(e.target.value);
                        },
                        type: props.type || "text"
                    }))
                }),
                /*#__PURE__*/ _jsxs("div", {
                    className: classNames(classes.addon, (_props_classes3 = props.classes) === null || _props_classes3 === void 0 ? void 0 : _props_classes3.addon),
                    children: [
                        props.suffixIcon && /*#__PURE__*/ _jsx("div", {
                            className: classes.suffix_icon,
                            children: props.suffixIcon
                        }),
                        clear && (value === null || value === void 0 ? void 0 : value.length) > 0 && /*#__PURE__*/ _jsx("div", {
                            className: classNames(classes.clear_icon, (_props_classes4 = props.classes) === null || _props_classes4 === void 0 ? void 0 : _props_classes4.clear),
                            children: /*#__PURE__*/ _jsx("img", {
                                src: require("../../assets/icons/clear.svg"),
                                onClick: function() {
                                    setValue("");
                                }
                            })
                        }),
                        props.maxLength && props.showMaxLength && /*#__PURE__*/ _jsxs("div", {
                            className: classes.max_length_tip,
                            children: [
                                (value === null || value === void 0 ? void 0 : value.length) || 0,
                                "/",
                                props.maxLength
                            ]
                        })
                    ]
                })
            ]
        })
    });
}
export default Input;

 //# sourceMappingURL=index.js.map